package chapter04

/**
 * @program lu-scala01
 * @description:  复杂的集合
 * @author: zhanglu
 * @create: 2022-04-08 22:52:00
 */
object Lu12_DerivedCollection {

  def main(args: Array[String]): Unit = {
    val l01 = List(1, 3, 5, 7, 2, 89)
    val l02 = List(3, 7, 2, 45, 4, 8, 19)

    //获取集合的头
    println(l01.head)
    //获取集合的尾(不是头的就是尾)
    println(l01.tail)
    //集合最后一个数据
    println(l01.last)
    //集合初始数据(不包含最后一个)
    println(l01.init)
    //反转
    println(l01.reverse)
    //取前后n个元素
    println(l01.take(3))
    println(l01.takeRight(4))
    //去掉前后n个元素
    println(l01.drop(3))
    println(l01.dropRight(4))
    //并集
    val union = l01:::l02
    println(union)
    println(union.distinct)
    //set并集会自动去重,无序
    val s1 = Set(1, 3, 5, 7, 2, 89)
    val s2 = Set(3, 7, 2, 45, 4, 8, 19)
    println(s1.union(s2))
    println(s1 ++ s2)
    //交集
    val intersection = l01.intersect(l02)
    println(intersection)
    println(s1.intersect(s2))
    //差集
    println(l01.diff(l02))  //属于l01不属于l02
    println(s1.diff(s2))  //属于s1不属于s2
    //拉链(对应位置的变为二元组)
    println(l01.zip(l02))
    println(s2.zip(s1))
    //滑窗 size:每个窗口大小 step:每次滑动步长
    println(l01.sliding(3))
    for(e <- l01.sliding(3)){
      println(e)
    }
    println("========")
    for(e <- l01.sliding(3, 2)){
      println(e)
    }

  }

}
